<?php
//defined('IN_MC') or exit('Access Denied');

class tcmc_cls
{
	/**
	 * 检查用户模块
	 * @param string $module_code
	 * @param string $content
	 * @param string $url
	 * @return 
	 */
	public static function check_admin_module($module_code, $content, $url = '')
	{
		$module_code = trim($module_code);
		if ($module_code != "")
		{
			global $admin_index_module_func;
			if ($admin_index_module_func == null)
			{
				$admin_index_module_func = new admin_index_module_func_cls();
			}
			global $_ADMIN_ID;
			if($admin_index_module_func->checkAdminIndexModule($_ADMIN_ID, $module_code) == true)
			{
				return;
			}
		}
		tcmc_cls::ShowMsg($content, $url);
	}
	
	/**
	 * 根据同一字段的值，合并两个一对多的数组
	 */
	public static function aaarray_merge( $arr1, $arr2, $same_filed, $new_filed_name='one_to_many')
	{
		if ( empty($arr1) )
		{
			return $arr2;
		}
		if ( empty($arr2) )
		{
			return $arr1;
		}
		foreach ($arr1 as $key => $val)
		{
			$new_arr[$key] = array_merge((array)$val, array());
			$many_arr = array();
			foreach ($arr2 as $k => $v)
			{
				if ($val[$same_filed] == $v[$same_filed])
				{
					$many_arr[] = array_merge($v, array());
					unset($arr2[$k]);
				}
			}
			$new_arr[$key][$new_filed_name]=$many_arr;
		}
		return $new_arr;
	}
	
	public static function array_to_where($arrayList, $field = "")
	{
		if ( is_array($arrayList) )
		{
			$al = array();
			$where = "(";			
			foreach ($arrayList as $info)
			{
				if ( is_array($info) )
				{
					if ($field != "")
					{
						if ( isset($info[$field]) )
						{
							if ( !in_array($info[$field], $al) )
							{
								$al[] = $info[$field];
								if ($where == "(")
								{
									$where .= "'" . $info[$field] . "'";
								}
								else
								{
									$where .= ", '" . $info[$field] . "'";
								}				
							}
						}
						else
						{
							return "";
						}
					}
					else
					{
						if ( !in_array($info[0], $al) )
						{
							$al[] = $info[0];
							if ($where == "(")
							{
								$where .= "'" . $info[0] . "'";
							}
							else
							{
								$where .= ", '" . $info[0] . "'";
							}				
						}
					}
				}
				else
				{
					if ( !in_array($info, $al) )
					{
						$al[] = $info;
						if ($where == "(")
						{
							$where .= "'" . $info . "'";
					}
						else
						{
							$where .= ", '" . $info . "'";
						}
					}		
				}
			}
			if ($where == "(")
			{
				return "";
			}
			return $where . ")";
		}
		return "";
	}
	
	public static function ShowMsg($msg,$gourl='',$limittime=3000,$onlymsg=0,$str = '')
	{
	
	$htmlhead  = "<!DOCTYPE HTML><html lang='zh-cn'>\r\n<head>\r\n<title>提示信息 - ".G_WEBNAME."</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n";
	if($str!="")
	{
		$htmlhead.="<script type='text/javascript' src='".$str."'></script>";
	}
    $note_css='note.css';
	$htmlhead .= "<base target='_self'/>\r\n<link href='/img/{$note_css}' rel='stylesheet' type='text/css' /></head>\r\n<body>".(isset($GLOBALS['ucsynlogin']) ? $GLOBALS['ucsynlogin'] : '')."\r\n<script type='text/javascript'>\r\n";
	$htmlfoot  = "</script>\r\n</body>\r\n</html>\r\n";

	$litime = ($limittime==0 ? 1000 : $limittime);
	$func = '';

	if($gourl=='-1')
	{
		if($limittime==0) $litime = 5000;
		$gourl = "javascript:history.go(-1);";
	}

	if($gourl=='' || $onlymsg==1)
	{
		$msg = "<script>alert(\"".str_replace("\"","“",$msg)."\");</script>";
	}else{
		//当网址为:close::objname 时, 关闭父框架的id=objname元素
		if(preg_match('/close::/isU',$gourl)){
			$tgobj = trim(preg_replace('/close::/isU', '', $gourl));
			$gourl = 'javascript:;';
			$func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
		}

		$func .= "      var pgo=0;
      function JumpUrl(){
        if(pgo==0){ location='$gourl'; pgo=1; }
      }\r\n";
		$rmsg = $func;
		$rmsg .= "document.write(\"<div class='notebox'><div class='notebox_in'><div class='head'></div><div class='body'><h3>提示信息:</h3>\");\r\n";
		$rmsg .= "document.write(\"<p>".str_replace("\"","“",$msg)."</p>\");\r\n";
		$rmsg .= "document.write(\"";
		if($onlymsg==0){
			if( $gourl != 'javascript:;' && $gourl != ''){
				$rmsg .= "<span>如果你的浏览器没反应，<a href='{$gourl}' class='btn'>请点击这里...</a></span>";
				$rmsg .= "</div></div></div>\");\r\n";
				$rmsg .= "setTimeout('JumpUrl()',$litime);";
			}else{
				$rmsg .= "</div></div></div>\");\r\n";
			}
		}else{
			$rmsg .= "</div></div></div>\");\r\n";
		}
		$msg  = $htmlhead.$rmsg.$htmlfoot;
	}
	echo $msg;
	exit;
	}
	
	public static function ShowMsg2($content, $url = "", $second = 3000)
	{
		echo "<html><head><title>提示信息 - ".G_WEBNAME."</title>
				<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
				<base target='_self'/>
				<link href='/img/note.css' rel='stylesheet' type='text/css' /><style>div{line-height:160%;}</style></head>
				<body leftmargin='0' topmargin='0'><center>
				<script>
      				var pgo=0;
      				function JumpUrl(){
        				if(pgo==0){ location='{$url}'; pgo=1; }
      				}
					document.write(" . '"' . "<div class='notebox'><div class='head'><div class='body'><h3>提示信息:</h3>" . '"' . ");
					document.write(" . '"' . "<p>{$content}</p>" . '"' . ");";
		if ($url != "")
		{
			echo "document.write(" . '"' . "<br />如果你的浏览器没反应，<a href='{$url}' class='btn'>请点击这里...</a></div></div> <div class='foot'></div></div>" . '"' . ");
					setTimeout('JumpUrl()', {$second});";
		}
		else
		{
			echo "document.write(" . '"' . "<br />如果你的浏览器没反应，<a href='javascript:history.go(-1)' class='btn'>请点击这里...</a></div></div> <div class='foot'></div></div>" . '"' . ");
					setTimeout('history.go(-1)', {$second});";
		}
		echo "</script>
				</center>
				</body>
				</html>";
		exit;
	}
	
}
?>